package com.changhong.framework.sdfs.namenode.server.nio;

import java.util.UUID;

/**
 * @author summer
 */
public class EditLog {
    /**
     * 请求Id标识
     */
    private String requestId;

    /**
     * 单个机器自增Id
     */
    private Long txId;

    /**
     * 数据内容
     */
    private String content;

    public EditLog(){

    }


    public static EditLogBuilder newBuilder(){
        return new EditLogBuilder();
    }


    static class EditLogBuilder{
        /**
         * 请求Id标识
         */
        private String requestId;

        /**
         * 单个机器自增Id
         */
        private Long txId;

        /**
         * 数据内容
         */
        private String content;


        public EditLogBuilder setRequestId(String requestId){
            this.requestId=requestId;
            return this;
        }

        public EditLogBuilder settxId(Long txId){
            this.txId=txId;
            return this;
        }

        public EditLogBuilder setContent(String content){
            this.content=content;
            return this;
        }

        public EditLog build(){
            EditLog editLog=new EditLog();
            if(requestId==null||"".equals(requestId)){
                editLog.setRequestId(UUID.randomUUID().toString());
            }else{
                editLog.setRequestId(requestId);
            }
            editLog.setTxId(txId);
            editLog.setContent(content);
            return editLog;
        }

    }


    public String getRequestId() {
        return requestId;
    }

    public void setRequestId(String requestId) {
        this.requestId = requestId;
    }

    public Long getTxId() {
        return txId;
    }

    public void setTxId(Long txId) {
        this.txId = txId;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    @Override
    public String toString() {
        return "EditLog{" +
                "requestId='" + requestId + '\'' +
                ", txId=" + txId +
                ", content='" + content + '\'' +
                '}';
    }
}
